package com.hspedu.collection_;

import java.util.HashSet;
import java.util.Objects;
@SuppressWarnings({"all"})
public class HashSetEx {
    public static void main(String[] args) {
        HashSet hashSet = new HashSet();
        Employ jack = new Employ("jack", 10);
        Employ merry = new Employ("merry", 20);
        Employ jack1 = new Employ("jack", 10);
        hashSet.add(jack);
        hashSet.add(merry);
        hashSet.add(jack1);
        System.out.println(hashSet);
    }
}

class Employ{
    private String name;
    private int age;

    public Employ(String name, int age) {
        this.name = name;
        this.age = age;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    @Override
    public String toString() {
        return "Employ{" +
                "name='" + name + '\'' +
                ", age=" + age +
                '}';
    }

//    public boolean equals(Object obj){
//        if(obj == this){
//            return true;
//        }
//
//        if(!(obj instanceof Employ)){
//            return true;
//        }
//        if(obj instanceof Employ){
//            Employ e = (Employ) obj;
//            if(this.name.equals(e.getName()) && this.age == e.getAge()){
//                return true;
//            }
//        }
//        return false;
//    }
//
//    public int hashCode(){
//        return 100;
//    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        Employ employ = (Employ) o;
        return age == employ.age && Objects.equals(name, employ.name);
    }

    @Override
    public int hashCode() {
        return Objects.hash(name, age);
    }
}